{literal}
<script type="text/javascript">
    $(document).ready(function(){
        $("#form_ajuste").validate({
            rules: {
				contrato_id: { required: true },
				data: { required: true },
				bln_credito: { required: true },
	            descricao: { required: true},
	            valor: { required: true, maxlength: 6}
            },
            messages: {
            	contrato_id: { required: "Selecione um Cliente" },
            	data: { required: "Obrigatorio" },
            	bln_credito: { required: "Obrigatorio" },
                descricao: { required: "Obrigatorio" },
                valor: {required: "Obrigatorio", maxlength: " 5 &eacute; o n&uacute;mero m&aacute;ximo de d&iacute;gitos aceitos para o valor"}
            },
            submitHandler: function(form) {
				jqAjaxForm(form, "div_mensagem");
			}
        });

        $("#contrato_id").numeric();
        $("#valor").priceFormat();

        $('#data').mask("99/99/9999");
        $('#data').datepick({showOn: 'both'});
        
    	$("#cod_cliente").autocomplete("contrato/complete-codigo", {
    		width: 400,
    		max: 10,
    		scroll: false,
    		scrollHeight: 500,
    		mustMatch:true,
    		delay:400,
    		formatItem: function(data, i, n, value) {
    			return value.split("::")[0]+" - "+value.split("::")[1];
    		},
    		formatResult: function(data, value) {
    			return value.split("::")[0];
    		}
    	});

    	$("#cod_cliente").result(function(event, data, formatted) {
    		if (data) {
    			$("#contrato_id").val(formatted.split("::")[0]);
    			$("#nome_cliente").val(formatted.split("::")[1]);
    		}
    	});

		//AUTO COMPLETE COM O NOME DE CLIENTES
    	$("#nome_cliente").autocomplete("contrato/complete-nome", {
    		width: 400,
    		max: 10,
    		scroll: false,
    		scrollHeight: 500,
    		mustMatch:true,
    		delay:400,
    		formatItem: function(data2, i2, n2, value2) {
				return value2.split("::")[0]+"  (Contrato: "+value2.split("::")[1]+")";
    		},
    		formatResult: function(data2, value2) {
    			return value2.split("::")[0];
				 
    		}
    	});

    	$("#nome_cliente").result(function(event2, data2, formatted2) {
    		if (data2){
    			$("#contrato_id").val(formatted2.split("::")[1]);
    			$("#cod_cliente").val(formatted2.split("::")[1]);
    		}
    	});
        
    }); //fecha $(
    
</script>
{/literal}
<form id="form_ajuste" name="form_ajuste" method="post" action="{$_site.url}{$acao}">
			<table width="100%" border="0" cellspacing="0" cellpadding="0" class="mvTituloFundo">
			  <tr>
				<td>
				{if $ajustefinanceiro->id > 0}Editar{else}Novo{/if} Ajuste Financeiro
				<input type="hidden" name="cod" value="{$ajustefinanceiro->id}"/>
				</td>
			  </tr>
			</table>
			<table width="100%" border="0" cellspacing="0" cellpadding="0">                
            <tr>
              <td class="contForm">
              <table width="100%" border="0" cellspacing="3" cellpadding="0">
               <tr>
               	  	<td valign="" class="fundoTituloForm">Cliente</td>
                 	<td colspan="3">
                 	<table width="100%">
                  		<tr>
                     		<td valign="top" class="bordaFormResp" width="20%">C&oacute;digo:</td>
                     		<td valign="top" class="bordaFormResp" width="80%">Nome:</td>
		 				</tr>
		 				<tr>
                     		<td valign="top" class="bordaFormResp"><input name="cod_cliente" type="text" class="formulario" id="cod_cliente" value="" size="10"/>
                     		<br><input type="hidden" name="contrato_id" id="contrato_id" value=""/>
                     		</td>
                     		<td valign="top" class="bordaFormResp"><input name="nome_cliente" type="text" class="formulario tamanhoForm" id="nome_cliente" value="" size="40"/></td>
						</tr>
             		</table>
                 </td>
 				</tr>
                <tr>
               		<td class="fundoTituloForm">Data</td>
                	<td colspan="3" class="bordaFormResp">
						<input name="data" type="text" class="formulario" id="data" value="{$smarty.now|date_format:"%d/%m/%Y"}" size="10"/>
                	</td>
				</tr>
				<tr>
                   	<td valign="top" class="fundoTituloForm">Valor:</td>
					<td class="bordaFormResp" colspan="3">
						<input name="valor" type="text" class="formulario" id="valor" value=""/>
					</td>
                 </tr>
                  <tr>
                    <td width="30%" valign="top" class="fundoTituloForm">Tipo de ajuste:</td>
                    <td class="bordaFormResp">
						<input type="radio" name="bln_credito" id="bln_credito" {if $ajustefinanceiro->bln_credito == 1}checked{/if} value="1" align="middle">CR&Eacute;DITO</input>&nbsp;&nbsp;
						<input type="radio" name="bln_credito" id="bln_credito" {if $ajustefinanceiro->bln_credito == 2}checked{/if} value="2" >D&Eacute;BITO</input>&nbsp;&nbsp;
                    </td>
                  </tr>
				<tr>
                   	<td valign="top" class="fundoTituloForm">Motivo do ajuste:</td>
					<td class="bordaFormResp" colspan="3">
						<input name="descricao" id="descricao" type="text" class="formulario tamanhoForm" value=""/ maxlength="200">
					</td>
                 </tr>
        		</table>
             </td>
           </tr>
   		  <tr>
             <td class="paddingTop15 paddingBottom15" align="center"><!-- === Botões ( Salvar e Limpar ) === -->
                 <span class="paddingRight15">
                 	<input type="submit" value="Salvar" class="botao">
                 </span>
               <span class="paddingRight15">
               <input name="limpar" type="reset" id="Limpar" value="Limpar" class="botao" />
               </span>
               <input type="button" value="Cancelar" onclick="cancelar(); return false;" class="botao">
                 <!-- Final === Botões ( Salvar e Limpar ) === -->                      </td>
           </tr>
           </table>	
    </form>
